function controlMotor(motor)
  if isPressed(LEFT) then
    forward(motor)
  elseif isPressed(RIGHT) then
    backward(motor)
  else 
    stop(motor)
  end
end

repeat
  if isTouched(1) then
    controlMotor(A)
  elseif isTouched(2) then
    controlMotor(B)
  else
    controlMotor(C)
  end
until isPressed(ESCAPE)
